<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>新增项目</title>
    <link rel="stylesheet" href="../utils/bootstrap-5.3.3-dist/css/bootstrap.min.css">
    <script src="../utils/bootstrap-5.3.3-dist/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="../utils/icon/iconfont.css">
    <link rel="stylesheet" href="../css/shared.css">
    <style>
        /*中部布局*/
        .central-layout {
            display: grid;
            grid-template-rows: 70px 470px 50px;
            width: 80vw;
            margin: 0 auto;
        }

        /*弹窗中部布局*/
        .dialog-body-layout {
            display: grid;
            grid-template-rows: auto auto;
        }

        /*波长设置布局*/
        .wave-layout {
            display: grid;
            grid-template-columns: 90px auto;
            align-items: start;
            padding: 5px;
        }

        .wave-right-layout {
            width: 100%;
            display: grid;
            grid-template-rows: auto auto auto;
            grid-gap: 5px;
        }

        .wave-right-inner-layout {
            display: grid;
            grid-template-rows: 30px auto;
            width: 100%;
            border: 1px solid black;
        }

        .wave-header {
            background-color: #c6c7c8;
            font-weight: bold;
            text-align: center;
        }

        .wave-body {
            display: grid;
            grid-template-columns: 80px 1fr;
            padding: 5px;
            gap: 5px;
        }
    </style>
</head>

<body>
    <div class="body-grid">
        <!--头部-->
        <div class="header-grid">
            <!--    返回按钮-->
            <div>
                <button class="btn btn-secondary iconfont go-back-button" onclick="window.location.href='index.html';">
                    &#xe623;
                </button>
            </div>
            <!--    标题-->
            <div class="page-title" id="page-title">
                <script>
                    document.getElementById("page-title").innerText = window.sessionStorage.getItem("competitionName") + "--新增项目"
                </script>
            </div>
            <div></div>
        </div>
        <!--中部-->
        <div class="central-layout">
            <div>
                <div style="width: 100%;margin-top: 15px;">
                    <button id="del-bh" class="btn btn-danger" style="float: left;"
                        onclick="openDialog('del-batch-project-dialog')">
                        批量删除
                    </button>
                    <button id="add-project-pop" type="button" class="btn btn-primary" style="float:right;"
                        onclick="openProjectDialog()">
                        新增项目
                    </button>
                    <div class="alert alert-danger" role="alert" style="width: 40%;margin:auto;" id="reasonableTime">

                    </div>

                </div>

                <!--            弹窗-->
                <div id="project-dialog" class="my-dialog" style="display: none;">
                    <div class="my-dialog-header">
                        <!--                    标题占位-->
                        <span>新增项目</span>
                        <button type="button" class="btn-close close-icon"
                            onclick="cancelProjectDialog('project-dialog')"></button>
                    </div>
                    <div class="my-dialog-body dialog-body-layout">
                        <div class="input-layout">
                            <div class="label-area">
                                <label for="project-type">类型<span style="color:red;">*</span>：</label>
                            </div>
                            <div class="input-area">
                                <select id="project-type" name="type" onchange="changeTypeAsync()">
                                    <option value="2">标准距离</option>
                                    <option value="1">中距离</option>
                                    <option value="0">短距离</option>
                                    <option value="3">快速</option>
                                    <option value="4">阳光</option>
                                </select>
                            </div>
                            <div class="err-area">
                                <small style="color: red;"></small>
                            </div>
                        </div>
                        <div class="wave-layout">
                            <div>
                                波长<span style="color:red;">*</span>：
                            </div>
                            <div class="wave-right-layout">
                                <div class="wave-right-inner-layout">
                                    <div class="wave-header">
                                        80m
                                    </div>
                                    <div class="wave-body">
                                        <label>
                                            个人
                                            <input id="80m-person-check" type="checkbox">
                                        </label>
                                        <label>
                                            开始时间<span style="color:red;">*</span>：
                                            <input id="80m-person-time" type="datetime-local">
                                        </label>
                                        <label>
                                            接力
                                            <input id="80m-relay-check" type="checkbox">
                                        </label>
                                        <label>
                                            开始时间<span style="color:red;">*</span>：
                                            <input id="80m-relay-time" type="datetime-local">
                                        </label>
                                    </div>
                                </div>
                                <div class="wave-right-inner-layout">
                                    <div class="wave-header">
                                        2m
                                    </div>
                                    <div class="wave-body">
                                        <label>
                                            个人
                                            <input id="2m-person-check" type="checkbox">
                                        </label>
                                        <label>
                                            开始时间<span style="color:red;">*</span>：
                                            <input id="2m-person-time" type="datetime-local">
                                        </label>
                                        <label>
                                            接力
                                            <input id="2m-relay-check" type="checkbox">
                                        </label>
                                        <label>
                                            开始时间<span style="color:red;">*</span>：
                                            <input id="2m-relay-time" type="datetime-local">
                                        </label>
                                    </div>
                                </div>
                                <small id="err-wave-body" style="color: red;"></small>
                            </div>
                        </div>
                    </div>

                    <div class="my-dialog-footer">
                        <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                            onclick="cancelProjectDialog('project-dialog')">取消
                        </button>
                        <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                            onclick="submitProjectDialog('project-dialog')">确认
                        </button>
                    </div>
                </div>
            </div>
            <!--    表格-->
            <div class="table-responsive">
                <table id="project-table" class="table table-sm table-bordered text-center"
                    style="width: 80%;margin:auto;margin-top:30px">
                    <thead>
                        <tr>
                            <th>
                                <label>
                                    全选
                                    <input type="checkbox" onclick="selectMul('project-table')">
                                </label>
                            </th>
                            <th>类型</th>
                            <th>波长</th>
                            <th>类别</th>
                            <th>开始时间</th>
                            <th>操作</th>
                        </tr>
                    </thead>
                    <tbody id="project-tbody" class="table-group-divider">

                    </tbody>
                </table>
            </div>
            <div>
                <!--    分页组件-->
                <ul class="pagination page-ul-flex" id="pagination">
                </ul>
            </div>


        </div>
        <!--尾部-->
        <div class="footer-grid">
            <!--网格留空-->
            <div></div>
            <!--进度条-->
            <div id="progress-bar" class="progress-bar-flex">
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">新增赛事</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">新增项目</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">设置组别</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">导入选手</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">下发号码</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">制卡</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">签到</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">批次管理</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">规则设置</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">开始比赛</div>
                    <i class="iconfont progress-bar-arrow">&#xe604;</i>
                </div>
                <div class="progress-bar-grid">
                    <button type="button" class="btn btn-success progress-bar-button" disabled></button>
                    <div class="progress-bar-text">成绩计算</div>
                    <i class="iconfont progress-bar-arrow" style="visibility: hidden;">&#xe604;</i>
                </div>
            </div>
            <!--   下一步-->
            <div>
                <button class="btn btn-primary iconfont next-button" onclick="nextProgress(GROUP_PROGRESS,'group.html')"
                    id="btn-progress">
                    &#xe65b;
                </button>
            </div>
        </div>
        <!--批量删除弹窗-->
        <div id="del-batch-project-dialog" class="my-dialog my-dialog-smaller" style="display: none">
            <div class="my-dialog-header">
                <!--                    标题占位-->
                <span>确定要批量删除吗？</span>
                <button type="button" class="btn-close close-icon"
                    onclick="closeDialog('del-batch-project-dialog')"></button>
            </div>
            <div class="my-dialog-body">
            </div>
            <div class="my-dialog-footer">
                <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                    onclick="closeDialog('del-batch-project-dialog')">取消
                </button>
                <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                    onclick="deleteBatchProject('project-table','del-batch-project-dialog')">确认
                </button>
            </div>
        </div>
        <!--单个删除弹窗-->
        <div id="del-one-project-dialog" class="my-dialog my-dialog-smaller" style="display: none">
            <div class="my-dialog-header">
                <!--                    标题占位-->
                <span>确定要删除吗？</span>
                <button type="button" class="btn-close close-icon"
                    onclick="closeDialog('del-one-project-dialog')"></button>
            </div>
            <div class="my-dialog-body">
            </div>
            <div class="my-dialog-footer">
                <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                    onclick="closeDialog('del-one-project-dialog')">取消
                </button>
                <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                    onclick="deleteOneProject('del-one-project-dialog')">确认
                </button>
            </div>
        </div>
        <!--编辑弹窗-->
        <div id="edit-dialog" class="my-dialog my-dialog-smaller" style="display: none">
            <div class="my-dialog-header">
                <!--                    标题占位-->
                <span>编辑开始时间</span>
                <button type="button" class="btn-close close-icon" onclick="closeDialog('edit-dialog')"></button>
            </div>
            <div class="my-dialog-body" style="display: grid;grid-template-rows: auto auto; padding: 5px">
                <label>
                    开始时间<span style="color:red;">*</span>：
                    <input type="datetime-local">
                </label>
                <small style="color:red;"></small>
            </div>
            <div class="my-dialog-footer">
                <button type="button" class="btn btn-secondary btn-sm my-dialog-ft-btn"
                    onclick="closeDialog('edit-dialog')">取消
                </button>
                <button type="button" class="btn btn-primary btn-sm my-dialog-ft-btn"
                    onclick="editProject('edit-dialog')">确认
                </button>
            </div>
        </div>
    </div>
    <script src="../js/pages.js"></script>
    <script src="../api/urls.js"></script>
    <script src="../js/dialog.js"></script>
    <script src="../js/progress.js"></script>
    <script src="../js/request.js"></script>
    <script>
        updateProgress("progress-bar", PROJECT_PROGRESS);
        //页码
        let pageNum = 1;
        //一页多少条
        let pageSize = 9;
        //总条数
        let total;
        //总页数
        let pages;
        //请求记录
        let records;
        //更新id
        let updateId;
        //删除id
        let delId;

        /**
         * 批量删除
         */
        async function deleteBatchProject(tableId, dialogId) {
            let deleteIds = [];
            let trs = document.querySelectorAll("#" + tableId + " tbody>tr");
            for (let tr of trs) {
                if (tr.firstElementChild.firstElementChild.checked) {
                    deleteIds.push(Number(tr.dataset.projectId));
                }
            }
            closeDialog(dialogId);
            if (deleteIds.length !== 0) {
                await fetch(PROJECT_URL + DELETE_BATCH_URL, {
                    method: "POST",
                    headers: new Headers({ "Content-Type": "application/json" }),
                    body: JSON.stringify(deleteIds)
                });
                await showPage();
            }
        }

        /**
         * 单个删除
         */
        async function deleteOneProject(dialogId) {
            closeDialog(dialogId);
            let url = new URL(PROJECT_URL + "/deleteById");
            url.searchParams.set("id", delId);
            await fetch(url, { method: "POST" });
            await showPage();
        }

        /**
         * 编辑开始时间
         */
        async function editProject(dialogId) {
            let value = document.querySelector("#" + dialogId + " .my-dialog-body input").value;
            if (!value) {
                document.querySelector("#" + dialogId + " .my-dialog-body small").textContent = "开始时间不能为空！";
                return;
            }
            if (new Date(window.sessionStorage.getItem("competitionTime")).getTime() > new Date(value).getTime()) {
                document.querySelector("#" + dialogId + " .my-dialog-body small").textContent = "开始时间不能小于赛事开始时间！";
                return;
            }
            closeDialog(dialogId);
            let url = new URL(PROJECT_URL + UPDATE_URL);
            url.searchParams.set("id", updateId);
            url.searchParams.set("startTime", value);
            await fetch(url, { method: "POST" });
            await showPage();
        }

        /**
         * 多选框实现
         */
        function selectMul(tableId) {
            let mulSelect = document.querySelector("#" + tableId + " thead input");
            let trs = document.querySelectorAll("#" + tableId + " tbody>tr");
            for (let tr of trs) {
                tr.firstElementChild.firstElementChild.checked = mulSelect.checked;
            }
        }

        /**
         * 判断是否有运动员
         */
        async function hasAthlete() {
            let url = new URL(ATHLETE_URL + "/hasOne");
            url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
            await fetch(url).then(resp => {
                return resp.json();
            }).then(result => {
                if (result.hasOne) {
                    let delBh = document.getElementById("del-bh");
                    delBh.disabled = true;
                    let dels = document.querySelectorAll("#project-tbody .btn-danger");
                    document.getElementById("add-project-pop").disabled = true;
                    for (let del of dels) {
                        del.disabled = true;
                    }
                }
            })
        }

        /**
         * 渲染表格
         */

        function drawProjectTable(records) {
            let mulSelect = document.querySelector("#project-table thead input");
            mulSelect.checked = false;
            let tableBody = document.getElementById("project-tbody");
            tableBody.innerHTML = "";
            for (let record of records) {
                let trElement = document.createElement("tr");
                trElement.dataset.projectId = record.id;
                let tdElement1 = document.createElement("td");
                let inputElement = document.createElement("input");
                inputElement.type = "checkbox";
                tdElement1.append(inputElement);
                let tdElement2 = document.createElement("td");
                switch (record.type) {
                    case 0:
                        tdElement2.textContent = "短距离";
                        break;
                    case 1:
                        tdElement2.textContent = "中距离";
                        break;
                    case 2:
                        tdElement2.textContent = "标准距离";
                        break;
                    case 3:
                        tdElement2.textContent = "快速";
                        break;
                    case 4:
                        tdElement2.textContent = "阳光";
                        break;
                    default:
                        console.log("分页数据错误");
                        break;
                }

                let tdElement3 = document.createElement("td");
                switch (record.frequency) {
                    case 0:
                        tdElement3.textContent = "80m";
                        break;
                    case 1:
                        tdElement3.textContent = "2m";
                        break;
                    default:
                        console.log("分页错误");
                        break;
                }
                let tdElement4 = document.createElement("td");
                switch (record.category) {
                    case 0:
                        tdElement4.textContent = "个人";
                        break;
                    case 1:
                        tdElement4.textContent = "接力";
                        break;
                    default:
                        console.log("分页错误");
                        break;
                }
                let tdElement5 = document.createElement("td");
                tdElement5.textContent = record.startTime.split("T")[0] + " " + record.startTime.split("T")[1].slice(0, -3);
                let tdElement6 = document.createElement("td");
                let buttonElement1 = document.createElement("button");
                buttonElement1.classList.add("btn", "btn-primary", "btn-sm", "iconfont");
                buttonElement1.style.marginRight = "10px";
                buttonElement1.textContent = "\u{e6f7}编辑";
                buttonElement1.addEventListener("click", () => {
                    updateId = record.id;
                    openEditDialog(String(record.startTime), "edit-dialog");
                });
                let buttonElement2 = document.createElement("button");
                buttonElement2.classList.add("btn", "btn-danger", "btn-sm", "iconfont");
                buttonElement2.textContent = "\u{e67c}删除";
                buttonElement2.addEventListener("click", () => {
                    delId = record.id;
                    openDialog("del-one-project-dialog");
                });
                tdElement6.append(buttonElement1, buttonElement2);
                trElement.append(tdElement1, tdElement2, tdElement3, tdElement4, tdElement5, tdElement6);
                tableBody.append(trElement);
            }
        }

        function openEditDialog(startTime, dialogId) {
            let element = document.querySelector("#" + dialogId + " .my-dialog-body input");
            document.querySelector("#" + dialogId + " .my-dialog-body small").textContent = "";
            element.value = startTime;
            openDialog(dialogId);
        }

        //实现分页的方法
        async function getPage(pageNum, pageSize) {
            //检查比赛项目是否合理
            let url2 = new URL(PROJECT_URL + "/checkReasonableProTime");
            url2.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
            fetch_http({
                url: url2,
                method: 'GET'
            }).then(r => {
                let reasonableTime = document.getElementById("reasonableTime")
                if (r.code == 200 && r.data == '合理') {
                    reasonableTime.style.display = 'none'
                } else {
                    reasonableTime.innerText=r.data;
                    reasonableTime.style.display = '';
                }
            })


            let url = new URL(PROJECT_URL + PAGE_URL);
            url.searchParams.set("pageNum", pageNum);
            url.searchParams.set("pageSize", pageSize);
            url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
            await fetch(url).then(response => {
                if (response.ok && response.headers.get("Content-Type") === "application/json") {
                    return response.json();
                } else {
                    throw new Error(`未知相应状态 ${response.status}或Content-Type：${response.headers.get("Content-Type")}`);
                }
            }).then(pageInfo => {
                pages = pageInfo.pages;
                total = pageInfo.total;
                records = pageInfo.records;
                if (records.length > 0) {
                    document.getElementById("btn-progress").disabled = false;
                } else {
                    document.getElementById("btn-progress").disabled = true;
                }
                drawProjectTable(records);
            }).catch(error => {
                console.log("分页错误：", error);
            });
            await hasAthlete();
        }

        //上一页
        async function prePage() {
            pageNum = pageNum - 1;
            await getPage(pageNum, pageSize);
            createpage(pageNum, pageSize, total, pages);
        }

        //下一页
        async function nextPage() {
            pageNum = pageNum + 1;
            await getPage(pageNum, pageSize);
            createpage(pageNum, pageSize, total, pages)
        }

        //点击切换
        async function handlePage(page) {
            if (page !== pageNum) {
                pageNum = page
                await getPage(pageNum, pageSize);
                createpage(pageNum, pageSize, total, pages);
            }

        }
        /**
         * 改变每页条数
         */
        async function changePageSize(value) {
            pageSize = Number(value);
            await getPage(pageNum, pageSize);
            createpage(pageNum, pageSize, total, pages);
        }

        // 创建分页组件
        async function showPage() {
            await getPage(pageNum, pageSize);
            createpage(pageNum, pageSize, total, pages);




        }

        showPage();

        //打开弹窗
        async function openProjectDialog() {
            await changeProjectType();
            openDialog('project-dialog');
        }

        async function changeTypeAsync() {
            await changeProjectType();
        }

        /**
         * 改变弹窗的项目类型
         */
        async function changeProjectType() {
            let projectType = document.getElementById('project-type');
            let elements = document.querySelectorAll(".wave-body");
            let checkedBoxs = document.querySelectorAll(".wave-body input[type='checkbox']:checked");
            for (let checkedBox of checkedBoxs) {
                checkedBox.checked = false;
            }
            for (let element of elements) {
                for (let child of element.children) {
                    child.style.visibility = "visible";
                }
            }
            if (projectType.value !== "0" && projectType.value !== "4") {
                for (let element of elements) {
                    element.children[2].style.visibility = "hidden";
                    element.children[3].style.visibility = "hidden";
                }
            }
            let url = new URL(PROJECT_URL + "/getByType");
            url.searchParams.set("type", projectType.value);
            url.searchParams.set("competitionId", window.sessionStorage.getItem("competitionId"));
            await fetch(url).then(response => {
                return response.json();
            }).then(projects => {
                for (const project of projects) {
                    if (project.frequency === 0) {//80m
                        if (project.category === 0) {//个人
                            elements[0].children[0].style.visibility = "hidden";
                            elements[0].children[1].style.visibility = "hidden";
                        } else {//接力
                            elements[0].children[2].style.visibility = "hidden";
                            elements[0].children[3].style.visibility = "hidden";
                        }
                    } else {//2m
                        if (project.category === 0) {//个人
                            elements[1].children[0].style.visibility = "hidden";
                            elements[1].children[1].style.visibility = "hidden";
                        } else {//接力
                            elements[1].children[2].style.visibility = "hidden";
                            elements[1].children[3].style.visibility = "hidden";
                        }
                    }
                }
            });
        }

        /**
         * 取消弹窗
         * @param dialogId
         */
        function cancelProjectDialog(dialogId) {
            let projectType = document.getElementById('project-type');
            projectType.value = "2";//标准距离
            projectType.parentElement.nextElementSibling.firstElementChild.textContent = "";
            let waveBodies = document.querySelectorAll(".wave-body");
            for (let waveBody of waveBodies) {
                waveBody.children[0].firstElementChild.checked = false;
                waveBody.children[1].firstElementChild.value = null;
                waveBody.children[2].firstElementChild.checked = false;
                waveBody.children[3].firstElementChild.value = null;
            }
            let elementById = document.getElementById("err-wave-body");
            elementById.textContent = "";
            closeDialog(dialogId);
        }

        /**
         * 新增项目
         * @param dialogId
         */

        async function submitProjectDialog(dialogId) {
            if (!verifyProjectForm()) {
                return;
            }
            let projectType = document.getElementById("project-type");
            let person80Check = document.getElementById("80m-person-check");
            let person2Check = document.getElementById("2m-person-check");
            let relay80Check = document.getElementById("80m-relay-check");
            let relay2Check = document.getElementById("2m-relay-check");
            let person80Time = document.getElementById("80m-person-time");
            let person2Time = document.getElementById("2m-person-time");
            let relay80Time = document.getElementById("80m-relay-time");
            let relay2Time = document.getElementById("2m-relay-time");
            let requestBody = [];
            let competitionId = window.sessionStorage.getItem("competitionId");
            if (person80Check.checked) {
                let project = {};
                project.type = projectType.value;
                project.frequency = "0";//80m
                project.category = "0";//个人
                project.startTime = person80Time.value;
                project.competitionId = competitionId;
                requestBody.push(project);
            }
            if (person2Check.checked) {
                let project = {};
                project.type = projectType.value;
                project.frequency = "1";//2m
                project.category = "0";//个人
                project.startTime = person2Time.value;
                project.competitionId = competitionId;
                requestBody.push(project);
            }
            if (relay2Check.checked) {
                let project = {};
                project.type = projectType.value;
                project.frequency = "1";//2m
                project.category = "1";//接力
                project.startTime = relay2Time.value;
                project.competitionId = competitionId;
                requestBody.push(project);
            }
            if (relay80Check.checked) {
                let project = {};
                project.type = projectType.value;
                project.frequency = "0";//80m
                project.category = "1";//接力
                project.startTime = relay80Time.value;
                project.competitionId = competitionId;
                requestBody.push(project);
            }
            await fetch(PROJECT_URL + "/addBatch", {
                method: "POST",
                headers: new Headers({ "Content-Type": "application/json" }),
                body: JSON.stringify(requestBody)
            });
            cancelProjectDialog(dialogId);
            await showPage();
        }

        /**
         * 新增项目校验
         */
        function verifyProjectForm() {
            let flag = true;
            let projectType = document.getElementById("project-type");
            let errWaveBody = document.getElementById("err-wave-body");
            let person80Check = document.getElementById("80m-person-check");
            let person2Check = document.getElementById("2m-person-check");
            let relay80Check = document.getElementById("80m-relay-check");
            let relay2Check = document.getElementById("2m-relay-check");
            let person80Time = document.getElementById("80m-person-time");
            let person2Time = document.getElementById("2m-person-time");
            let relay80Time = document.getElementById("80m-relay-time");
            let relay2Time = document.getElementById("2m-relay-time");
            if (!projectType.value) {
                projectType.parentElement.nextElementSibling.firstElementChild.textContent = "类型不能为空！";
                flag = false;
            } else if (projectType.value !== "0" && projectType.value !== "4") {
                if (relay80Check.checked || relay2Check.checked) {
                    errWaveBody.textContent = "除短距离和阳光以外均无接力赛！";
                    flag = false;
                }
            }
            if (!person80Check.checked && !person2Check.checked && !relay2Check.checked && !relay80Check.checked) {
                errWaveBody.textContent = "项目不能为空！";
                flag = false;
                return flag;
            }
            if ((person80Check.checked && !person80Time.value) ||
                (person2Check.checked && !person2Time.value) ||
                (relay80Check.checked && !relay80Time.value) ||
                (relay2Check.checked && !relay2Time.value)) {
                errWaveBody.textContent = "不能存在开始时间为空的项目！";
                flag = false;
                return flag;
            }

            if ((person80Check.checked && new Date(window.sessionStorage.getItem("competitionTime")).getTime() > new Date(person80Time.value).getTime()) ||
                (person2Check.checked && new Date(window.sessionStorage.getItem("competitionTime")).getTime() > new Date(person2Time.value).getTime()) ||
                (relay80Check.checked && new Date(window.sessionStorage.getItem("competitionTime")).getTime() > new Date(relay80Time.value).getTime()) ||
                (relay2Check.checked && new Date(window.sessionStorage.getItem("competitionTime")).getTime() > new Date(relay2Time.value).getTime())) {
                errWaveBody.textContent = "开始时间不能小于赛事开始时间！";
                flag = false;
                return flag;
            }
            console.log(new Date(window.sessionStorage.getItem("competitionEndTime")))
            if ((person80Check.checked && new Date(window.sessionStorage.getItem("competitionEndTime")).getTime() + 86399900 < new Date(person80Time.value).getTime()) ||
                (person2Check.checked && new Date(window.sessionStorage.getItem("competitionEndTime")).getTime() + 86399900 < new Date(person2Time.value).getTime()) ||
                (relay80Check.checked && new Date(window.sessionStorage.getItem("competitionEndTime")).getTime() + 86399900 < new Date(relay80Time.value).getTime()) ||
                (relay2Check.checked && new Date(window.sessionStorage.getItem("competitionEndTime")).getTime() + 86399900 < new Date(relay2Time.value).getTime())) {
                errWaveBody.textContent = "开始时间不能大于赛事结束时间！";
                flag = false;
                return flag;
            }

            if (person80Check.checked && person80Time.value) {
                if ((person2Check.checked && person80Time.value === person2Time.value) ||
                    (relay80Check.checked && person80Time.value === relay80Time.value) ||
                    (relay2Check.checked && person80Time.value === relay2Time.value)) {
                    errWaveBody.textContent = "不能存在开始时间相等的项目！";
                    flag = false;
                    return flag;
                }

                if ((person2Check.checked && person80Time.value === person2Time.value) ||
                    (relay80Check.checked && person80Time.value === relay80Time.value) ||
                    (relay2Check.checked && person80Time.value === relay2Time.value)) {
                    errWaveBody.textContent = "不能存在开始时间相等的项目！";
                    flag = false;
                    return flag;
                }

            }
            if (person2Check.checked && person2Time.value) {
                if ((person80Check.checked && person2Time.value === person80Time.value) ||
                    (relay80Check.checked && person2Time.value === relay80Time.value) ||
                    (relay2Check.checked && person2Time.value === relay2Time.value)) {
                    errWaveBody.textContent = "不能存在开始时间相等的项目！";
                    flag = false;
                    return flag;
                }
            }
            if (relay2Check.checked && relay2Time.value) {
                if ((person2Check.checked && relay2Time.value === person2Time.value) ||
                    (relay80Check.checked && relay2Time.value === relay80Time.value) ||
                    (person80Check.checked && relay2Time.value === person80Time.value)) {
                    errWaveBody.textContent = "不能存在开始时间相等的项目！";
                    flag = false;
                    return flag;
                }
            }
            if (relay80Check.checked && relay80Time.value) {
                if ((person2Check.checked && relay80Time.value === person2Time.value) ||
                    (person80Check.checked && relay80Time.value === person80Time.value) ||
                    (relay2Check.checked && relay80Time.value === relay2Time.value)) {
                    errWaveBody.textContent = "不能存在开始时间相等的项目！";
                    flag = false;
                    return flag;
                }
            }


            return flag;
        }

    </script>
</body>

</html>